package com.example;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * Root resource (exposed at "myresource" path)
 */
@Path("myresource")
public class MyResource {

    /**
     * You need to config the follow parameters as you need.
     */
	private static final String PROXYIP="proxy.xxxx.yyyy.zzzz";
	private static final String PROXYPORT="8080";
	private static final String CHANNEL_FIRST="http://www.xxxx.com/wwww.html";
	private static final String CHANNEL_SECOND="http://www.yyyy.com/wwww.html";
	private static final String QUERYPARAMETER1="depdate";
	private static final String QUERYPARAMETER2="rtndate";
	private static final String QUERYPARAMETER3="cabin";
	private static final String QUERYPARAMETER4="adult";
	private static final String QUERYPARAMETER5="child";
	private static final String QUERYPARAMETER6="infant";
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public Response getIt(@QueryParam(QUERYPARAMETER1) String depdate,
    		@QueryParam(QUERYPARAMETER2) String rtndate,
    		@QueryParam(QUERYPARAMETER3) String cabin,
    		@QueryParam(QUERYPARAMETER4) String adult,
    		@QueryParam(QUERYPARAMETER5) String child,
    		@QueryParam(QUERYPARAMETER6) String infant) {
    	System.setProperty("http.proxyHost", PROXYIP);
    	System.setProperty("http.proxyPort", PROXYPORT);
    	System.setProperty("https.proxyHost", PROXYIP);
    	System.setProperty("https.proxyPort", PROXYPORT);
    	Response airPlaneTicketsInfoResponse = ClientBuilder.newBuilder()
    			.build()
    			.target(CHANNEL_FIRST)
    			.queryParam(QUERYPARAMETER1, depdate)
    			.queryParam(QUERYPARAMETER2, rtndate)
    			.queryParam(QUERYPARAMETER3, cabin)
    			.queryParam(QUERYPARAMETER4, adult)
    			.queryParam(QUERYPARAMETER5, child)
    			.queryParam(QUERYPARAMETER6, infant)
    			.request()
    			.get();
    	/**Here I can't resolve the json data in the response,
    	 * because I haven't got an example or the structure of the data.
    	 * All of this will be done while you give me a channel to test.*/
    	return Response.ok().entity(airPlaneTicketsInfoResponse.getEntity()).build();
    }
}
